/**
 * grid
 * @authors sylthas (sylthasgg@gmail.com)
 * @date    2014-07-12 00:54:37
 * @version $Id$
 */
$(function () {

    var nodes = [{
        id: '000',
        text: '未来公司',
        img: 'icon-folder',
        nodes: [{
            id: 1,
            text: 'Google',
            img: 'icon-page'
        }, {
            id: 2,
            text: 'Baidu',
            img: 'icon-page'
        }, {
            id: 3,
            text: 'Microsoft',
            img: 'icon-page'
        }]
    }];

    $('#grid').w2grid({ 
        name: 'grid', 
        show: { 
            toolbar: true,
            footer: true
        },
        columns: [                
            { field: 'recid', caption: 'ID', size: '50px', sortable: true, resizable: true },
            { field: 'text', caption: 'text', size: '120px', sortable: true, resizable: true, 
                editable: { type: 'etree' ,nodes: nodes},
                render: function(rcd,index,col_index) {
                    var html = this.getCellValue(index, col_index);
                    return {'1':'Google','2':'Baidu','3':'Microsoft'}[html] || '';
                }
            }
        ],
        records: [
            { recid: 1, text: 1 },
            { recid: 2, text: 2 }
        ]
    }); 

    $('#btn').on('click', function(){
        var ret = w2ui.grid.getChanges();
        console.dir(ret);
    });
});
